//
//  LHCityView.m
//  Knight_Tour
//
//  Created by Bruce_Lin on 15/5/13.
//  Copyright (c) 2015年 TouchOne. All rights reserved.
//

#import "LHCityView.h"
#import "LHCityCollectionViewCell.h"
#import "LHCityModel.h"
#import "UIImageView+WebCache.h"

@implementation LHCityView

- (void)dealloc
{
    [_cityCollectonView release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        [self creatView];
    }
    return self;
}

- (void)creatView
{
    UICollectionViewFlowLayout *fly = [[UICollectionViewFlowLayout alloc]init];
    [fly setItemSize:CGSizeMake(LHWidth/3 - 20, (LHheight - 64) / 4)];
    [fly setSectionInset:UIEdgeInsetsMake(5, 10, 5, 10)];
    
    self.cityCollectonView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) collectionViewLayout:fly];
    _cityCollectonView.delegate = self;
    _cityCollectonView.dataSource = self;
    _cityCollectonView.backgroundColor = [UIColor colorWithRed:0.871 green:0.962 blue:0.965 alpha:1.000];
    [self addSubview:_cityCollectonView];
    [_cityCollectonView registerClass:[LHCityCollectionViewCell class] forCellWithReuseIdentifier:@"cityReuse"];
    [fly release];
    [_cityCollectonView release];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.CityArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LHCityCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cityReuse" forIndexPath:indexPath];
//    [cell.cityPicView sd_setImageWithURL:[NSURL URLWithString:[self.CityArr[indexPath.item] pic]]];
    [cell.cityPicView sd_setImageWithURL:[NSURL URLWithString:[self.CityArr[indexPath.item]pic]] placeholderImage:[UIImage imageNamed:@"word4"]];
    cell.cityName.text = [self.CityArr[indexPath.item] namec];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self.delegate jumpToSightWithIndexPath:indexPath];
}
@end
